import java.lang.reflect.Array;
import java.util.Arrays;
public class TextArray {
    //冒泡排序
    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            boolean flg = false;
            for (int j = 0; j < array.length-1; j++) {
                if(array[j] > array[j+1]) {
                    int  tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if (flg == false)//说明有序了
            {
                return;
            }
        }
    }
    public static void main(String[] args) {
        int[] array = {1,12,31,4,5};
        System.out.println(Arrays.toString(array));
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void print(int[] array) {
        for(int i = 0; i<array.length;i++) {
            System.out.print(array[i]+" ");
        }
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4};
        int[] array2 = new int[]{1,2,3,4};
        int[] array3 = new int[10];//定义数组时确定长度
        System.out.println("数值长度:"+array.length);
        System.out.println("数值长度:"+array2.length);
        System.out.println("数值长度:"+array3.length);
        //遍历数组
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();//换行
        //如果只是遍历程序，用for-each
        for (int x:array) {
            System.out.print(x+" ");
        }
        System.out.println();
        //Arrays.toString(array);是将数组转化为字符串(String)的方式输出
        String ret = Arrays.toString(array);
        System.out.println(ret);
        System.out.println();
        //局部变量，引用变量
        int[] array4 = {1,2,3,4};
        print(array);//引用方法print
    }
}
